const tableEle = document.querySelector('table')
/**
 * 显示购物车列表
 */
function showCartList() {
	let cartList = localStorage.getItem('CART-LIST') || '[]'
	cartList = JSON.parse(cartList) // 购物车数组

	let str = `<tr>
                    <th>序号</th>
                    <th>商品图片</th>
                    <th>商品名称</th>
                    <th>单价</th>
                    <th>数量</th>
                    <th width="100px">总价</th>
                    <th>操作</th>
                </tr>`
	let arr = cartList.map(item => {
		return `<tr>
                        <td>${item.id}</td>
                        <td><img src="${item.url}" alt="pic1"/></td>
                        <td>${item.name}</td>
                        <td>${item.price}</td>
                        <td><input type="button" value="-" name="minus"  ${item.num == 0 ? 'disabled' : ''}    data-id="${item.id}"/>
                        <input type="text" value="${item.num}" name="amount"/>
                        <input type="button" value="+"  name="plus"  data-id="${item.id}" /></td>
                        <td>${item.num * item.price}</td>
                        <td>移入收藏<br /><a href="javascript:void(0)" class="del" data-id="${item.id}">删除</a></td>
                    </tr>`
	})
	tableEle.innerHTML = str + arr.join('')
}


showCartList()